<?php use_helper('DateForm') ?>

<form action=<?php echo url_for('transaction/budgetreport')?>>
Filter records 
From <?php echo input_date_tag('startdate', $startdate, 'rich=true') ?> &nbsp;
To <?php echo input_date_tag('enddate', $enddate, 'rich=true') ?> &nbsp;
<input type=submit value=Filter>
</form>
<form action=<?php echo url_for('transaction/budgetreport')?>>
<input type=submit value=Reset>
</form>

<h1>Budget Report</h1>
<b>Current Balance: <?php echo MyDecimal::format($currentbalance) ?></b>
<br>
<br>
<table>
  <thead>
    <tr>
      <th>Edit</th>
      <th> | </th>
      <th>ID</th>
      <th> | </th>
      <th>Date</th>
      <th> | </th>
      <th>Description</th>
      <th> | </th>
      <th>Income</th>
      <th> | </th>
      <th>Expense</th>
      <th> | </th>
      <th>Account</th>
      <th> | </th>
      <th>Balance</th>
    </tr>
  </thead>
  <tbody>
    <?php 
      $balance=$initialbalance;
      foreach ($transaction_list as $transaction): 
      $balance+=$transaction->getincome()-$transaction->getexpense();
    ?>
    <tr>
      <td><a href="<?php echo url_for((($transaction->getAccountId()==null)?'income':'expense').'/edit?id='.$transaction['id']) ?>">Edit</a></td>
      <td> | </td>
      <td><?php echo $transaction->getId() ?></td>
      <td> | </td>
      <td><?php echo MyDateTime::fromdate($transaction->getdate())->toprettydate() ?></td>
      <td> | </td>
      <td><?php echo $transaction->getdescription() ?></td>
      <td> | </td>
      <td align=right><?php echo ($transaction->getincome()>0)?MyDecimal::format($transaction->getincome()):"" ?></td>
      <td> | </td>
      <td align=right><?php echo ($transaction->getexpense()>0)?MyDecimal::format($transaction->getexpense()):"" ?></td>
      <td> | </td>
      <td ><?php echo ($transaction->isIncome())?$transaction->getIncomeAccount():$transaction->getAccount() ?></td>
      <td> | </td>
      <td align=right><?php echo MyDecimal::format($balance) ?></td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>


<br>
<?php if ($pager->haveToPaginate()): ?>
  <div class="pagination">
    <a href="<?php echo url_for('transaction/budgetreport?startdate='.$startdate.'&enddate='.$enddate) ?>&page=1"><img src="/images/first.png" alt="First page" /></a>
    <a href="<?php echo url_for('transaction/budgetreport?startdate='.$startdate.'&enddate='.$enddate) ?>&page=<?php echo $pager->getPreviousPage() ?>"><img src="/images/previous.png" alt="Previous page" title="Previous page" /></a>
    <?php foreach ($pager->getLinks() as $page): ?>
      <?php if ($page == $pager->getPage()): ?>
         <?php echo $page ?>
      <?php else: ?>
         <a href="<?php echo url_for('transaction/budgetreport?startdate='.$startdate.'&enddate='.$enddate) ?>&page=<?php echo $page ?>"><?php echo $page ?></a>
      <?php endif; ?>
    <?php endforeach; ?>
     <a href="<?php echo url_for('transaction/budgetreport?startdate='.$startdate.'&enddate='.$enddate) ?>&page=<?php echo $pager->getNextPage() ?>"><img src="/images/next.png" alt="Next page" title="Next page" /></a>
     <a href="<?php echo url_for('transaction/budgetreport?startdate='.$startdate.'&enddate='.$enddate) ?>&page=<?php echo $pager->getLastPage() ?>"><img src="/images/last.png" alt="Last page" title="Last page" /></a>
  </div>
<?php endif; ?>
<div class="pagination_desc">
   Total records: <strong><?php echo $pager->getNbResults() ?></strong>
  <?php if ($pager->haveToPaginate()): ?>
     - page <strong><?php echo $pager->getPage() ?>/<?php echo $pager->getLastPage() ?></strong>
  <?php endif; ?>
</div>



